package org.tailor
class LoginTailorController {
    
  def scaffold = LoginTailor
  
  def login = {}
  
  def authenticate = {
    def loginTailor = LoginTailor.findByLoginAndPassword(params.login, params.password)
    if(loginTailor){
      session.loginTailor = LoginTailor
      flash.message = "Hello ${loginTailor.name}!"
      redirect(controller:"tailor", action:"list")      
    }else{
      flash.message = "Sorry, ${params.login}. Please try again."
      redirect(action:"login")
    }
  }
  
  def logout = {
    flash.message = "Goodbye ${session.loginTailor.name}"
    session.loginTailor = null
    redirect(controller:"tailor", action:"list")      
  }  
}